//
//  NewEventTextFieldCell.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/22.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit

class NewEventTextFieldCell: NewEventViewBasicCell {
    
    @IBOutlet var textFieldRightBtn: UIButton!
    
    @IBOutlet weak var textField: UITextField!
    
    @IBOutlet weak var underLineView: UIView!
    
    var isSelecting: Bool = false {
        didSet {
            if isRightBtnAction{
                if isSelecting {
                    UIView.animateWithDuration(0.4, animations: {
                        self.textFieldRightBtn.layer.setAffineTransform(CGAffineTransformRotate(self.transform, CGFloat( M_PI)))
                    })
                }else {
                    UIView.animateWithDuration(0.4, animations: {
                        self.textFieldRightBtn.layer.setAffineTransform(CGAffineTransformRotate(self.transform, CGFloat(2*M_PI)))
                    })
                }
            }
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        notify.addObserverForName(UITextFieldTextDidChangeNotification, object: textField, queue: nil, usingBlock: {_ in
            if self.textField.text == "" {
                self.underLineView.backgroundColor = YOKOColor.backImageColor
                self.iconView?.highlighted = false
            }else {
                self.underLineView.backgroundColor = YOKOColor.TypeColors[1]
                self.iconView?.highlighted = true
            }
            
        })
    }
    
    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        
        textField.placeholder = self.cellTitle
        textFieldRightBtn.setBackgroundImage(UIImage(named: self.rightBtnImgName), forState: .Normal)
                
    }
    
    @IBAction func selectingEventType(sender: UIButton) {
        
        isSelecting = !isSelecting
        
        if !self.isRightBtnAction{
            return
        }
        self.delegate.selectingEventType()
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
